﻿namespace zielonka.co.uk.extensions.Generic.class_
{
    /*example
        MyClass myClass = Provider.GetSomeResult();
        string temp = myClass.Safe().SomeValue;
        instead of:

        MyClass myClass = Provider.GetSomeResult();
        string temp = "some default value";
        if (myClass != null)
        {
                temp = myClass.SomeValue;
        }
      */
    public static partial class ClassExtensions
    {
        public static T Safe<T>(this T obj) where T : new()
        {
            if (obj == null)
            {
                obj = new T();
            }
            return obj;
        }
    }
}
